/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package my.algorithms.mcorrea;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;

/**
 *
 * @author mcorrea
 */
public class MainTest {
	
	public static void main(String args[]){
		
		List<Product> products = new  ArrayList<Product>();
		
		Product search2 = new Product("iphone");
		
		products.add(new Product("xbox"));
		products.add(new Product("android"));
		products.add(search2);
		products.add(new Product("iphone"));  
		
		//Binary search by String 
		Product search =  new Product("iphone");
		
		int result = Collections.binarySearch(products, search,
				new Comparator<Product>(){
					@Override
					public int compare(Product o1, Product o2) {
						return o1.getName().compareTo(o2.getName());
					}
				});
				
		System.out.println("result1: "+ result);
		
		//Binary search on object by ID 
		//int result2 = Collections.binarySearch(products, search2); 
		//System.out.println("result 2: "+ result2);
		 
		 
		
		for(Product p : products){
			if(p.getName().contains("a"))
				System.out.println(p);
		}
		
		
		
	
	}
	
}
